
/******************************************************************************
 *
 * jattbak - TODO
 *
 * Author:        Dennis Krzyzaniak
 * E-mail:        ebrosius@netgarage.org
 * Copyright (C): 2011 by Dennis Krzyzaniak
 *
 * This file is part of jattbak.
 *
 * jattbak is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * jattbak is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with jattbak.  If not, see <http://www.gnu.org/licenses/>.
 *
 *****************************************************************************/

/**
 * AmigaOS-style double linked list
 */

#ifndef __JATTBAK_DLIST_H__
#define __JATTBAK_DLIST_H__

/* =========== INCLUDES ==================================================== */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

/* =========== DEFINES ===================================================== */

/* =========== DATA TYPES ================================================== */

struct baseDlistNode_s {
   struct baseDlistNode_s* successor;
   struct baseDlistNode_s* ancestor;
};
typedef struct baseDlistNode_s baseDlistNode_t;


struct baseDlist_s {
   baseDlistNode_t* head;
   baseDlistNode_t* tail;
   baseDlistNode_t* tailPred;
};
typedef struct baseDlist_s baseDlist_t;

/* =========== PUBLIC PROTOTYPES =========================================== */

/*---------------------------------------------------------------------------*/
void
baseDlistInit(
      baseDlist_t* const list
      );
/*---------------------------------------------------------------------------*/

/*---------------------------------------------------------------------------*/
void
baseDlistAddHead(
      baseDlist_t* const list,
      baseDlistNode_t* const node
      );
/*---------------------------------------------------------------------------*/

/*---------------------------------------------------------------------------*/
void
baseDlistAddTail(
      baseDlist_t* const list,
      baseDlistNode_t* const node
      );
/*---------------------------------------------------------------------------*/

/*---------------------------------------------------------------------------*/
void
baseDlistInsertBefore(
      baseDlist_t* const list,
      baseDlistNode_t* const successor,
      baseDlistNode_t* const node
      );
/*---------------------------------------------------------------------------*/

/*---------------------------------------------------------------------------*/
void
baseDlistInsertAfter(
      baseDlist_t* const list,
      baseDlistNode_t* const ancestor,
      baseDlistNode_t* const node
      );
/*---------------------------------------------------------------------------*/

/*---------------------------------------------------------------------------*/
baseDlistNode_t*
baseDlistRemove(
      baseDlistNode_t* const node
      );
/*---------------------------------------------------------------------------*/

/*---------------------------------------------------------------------------*/
baseDlistNode_t*
baseDlistRemoveHead(
      baseDlist_t* const list
      );
/*---------------------------------------------------------------------------*/

/*---------------------------------------------------------------------------*/
int
baseDlistGetItemCount(
      const baseDlist_t* const list
      );
/*---------------------------------------------------------------------------*/

/*---------------------------------------------------------------------------*/
#define baseDlistGetHead(list) \
   ((list)->head->successor != NULL ? (list)->head : NULL)
/*---------------------------------------------------------------------------*/

/*---------------------------------------------------------------------------*/
#define baseDlistGetTail(list) \
   ((list)->tailPred->ancestor != NULL ? (list)->tailPred : NULL)
/*---------------------------------------------------------------------------*/

/*---------------------------------------------------------------------------*/
#define baseDlistGetSuccessor(node) \
   ((node)->successor->successor != NULL ? (node)->successor: NULL)
/*---------------------------------------------------------------------------*/

/*---------------------------------------------------------------------------*/
#define baseDlistGetAncestor(node) \
   ((node)->ancestor->ancestor != NULL ? (node)->ancestor : NULL)
/*---------------------------------------------------------------------------*/

#endif /* __JATTBAK_DLIST_H__ */

/* ========================== END OF FILE ================================== */

/*
 * vim settings, please do not remove!
 * vim:autoindent:filetype=c:syntax=c:
 * vim:ts=3:sw=3:sts=3:expandtab:cindent:tw=75:formatoptions=croql:
 * vim600:foldmethod=syntax:
 */

